home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / O Boy / Source / O Boy.c < prev    next >
C/C++ Source or Header  |  1996-06-21  |  3KB  |  161 lines

  1. // main file ... from the C.Spathis Shell (ty Gus)
  2. //
  3. #define __MAIN__
  4.  
  5. #include <quickdraw.h>
  6. #include <drag.h>
  7. #include <gestaltEqu.h>
  8. #include "O Boy.h"
  9. #include "OBoy_hi.h"
  10.  
  11. Boolean InitMacToolbox(void);
  12. Boolean InitApplication(void);
  13.  
  14. #define kMinSize    1
  15.  
  16. Boolean TrapAvailable(short tNumber,TrapType tType);
  17. long HeapNeeded(void);
  18. long StackNeeded(void);
  19.  
  20.  
  21.  
  22. void main(void)
  23. {
  24.     Boolean    done=FALSE;
  25.     
  26.     if (InitMacToolbox()){
  27.         if (InitApplication()){
  28.             while(!done){
  29.                 done=DoEvents();
  30.             }
  31.         }
  32.     }
  33.     ExitApp();
  34. }
  35. void ExitApp(void)
  36. {
  37.     
  38. }
  39. Boolean InitMacToolbox(void)
  40. {
  41.     Boolean    ret=TRUE;
  42.     SysEnvRec envRec;
  43.     long stkNeeded, heapSize;
  44.     long    response;
  45.     
  46.     // initialize Mac Toolbox components
  47.     InitGraf( &qd.thePort);
  48.     InitFonts();
  49.     InitWindows();
  50.     InitMenus();
  51.     TEInit();
  52.     InitDialogs(nil);
  53.     InitCursor();
  54.     
  55.     if (Gestalt(gestaltDragMgrAttr, &response) != noErr){
  56.         Draggable=false;
  57.     }else{
  58.         Draggable=true;
  59.     }        
  60.  
  61.     // ignore the error returned from SysEnvirons; even if an error occurred,
  62.     // the SysEnvirons glue will fill in the SysEnvRec
  63.     (void) SysEnvirons(curSysEnvVers, &envRec);
  64.     
  65.     // Are we running on a 128K ROM machine or better???
  66.     if (envRec.machineType < 0){
  67.         //BigBadError(kErrStrings,eWrongMachine);        // if not, alert & quit
  68.         ret=FALSE;
  69.     }
  70.  
  71.     // if we need more stack space, get it now
  72.     stkNeeded = StackNeeded(); 
  73.     if (stkNeeded > StackSpace()){
  74.         // new address is heap size + current stack - needed stack
  75.         SetApplLimit((Ptr) ((long) GetApplLimit() - stkNeeded + StackSpace()));
  76.     }
  77.  
  78.     // Check for minimum heap size
  79.     heapSize = (long) GetApplLimit() - (long) ApplicZone();
  80.     if (heapSize < HeapNeeded()){
  81.         //BigBadError(kErrStrings,eSmallSize);
  82.         ret=FALSE;
  83.     }
  84.  
  85.     // expand the heap so new code segments load at the top
  86.     MaxApplZone();
  87.     for (Int16 i = 1; i <= 101; i++) {
  88.         MoreMasters();
  89.     }
  90.  
  91.     bHaveWaitNextEvent = TrapAvailable(_WaitNextEvent, ToolTrap);
  92.  
  93.     return ret;
  94. }
  95. Boolean TrapAvailable(short tNumber,TrapType tType)
  96. {
  97.     // Check and see if the trap exists. On 64K ROM machines, tType will be ignored.
  98. #ifndef powerc
  99.     return NGetTrapAddress(tNumber, tType) != GetTrapAddress(_Unimplemented);
  100. #else
  101.     return true;
  102. #endif
  103.  
  104. Boolean InitApplication(void)
  105. {
  106.     Boolean    ret=TRUE;
  107.     Handle    menuBar;
  108.     
  109.     // read menus into menu bar
  110.     if ((menuBar = GetNewMBar(MAIN_MENU_BAR))!=nil){
  111.         // install menus
  112.         SetMenuBar(menuBar);
  113.         DisposHandle(menuBar);
  114.         // add DA names to Apple menu
  115.         AddResMenu(GetMHandle(APPLE_MENU), 'DRVR');
  116.         DrawMenuBar();
  117.         
  118.         sleepTime=10;
  119.         EventInit();
  120.          gSelfPSN.highLongOfPSN = 0;
  121.          gSelfPSN.lowLongOfPSN = kCurrentProcess;        //* Use this instead of GetCurrentProcess *//
  122.          if (AECreateDesc(typeProcessSerialNumber,(Ptr)&gSelfPSN,sizeof(ProcessSerialNumber),&gSelfAddress)!=0){
  123.              return FALSE;
  124.          }
  125.         gNullDesc.descriptorType = typeNull;        // Initialize the global null descriptor record.
  126.         gNullDesc.dataHandle = nil;
  127.         
  128.  
  129.         // gestalt check time
  130.         {
  131.             Int_32    theFeature;
  132.             if( Gestalt( gestaltFinderAttr, &theFeature ) == noErr )
  133.             {
  134.                 if( (theFeature & (1 << gestaltOSLCompliantFinder ) ) == 0 )
  135.                 {
  136.                     StopAlert( 130,nil );
  137.                     ret = FALSE;
  138.                 }
  139.             }
  140.         }
  141.  
  142.         if( ret == TRUE )
  143.         {
  144.             OBoy_hi    *theHumanInterface = new OBoy_hi;
  145.         }
  146.     }else{
  147.         ret=FALSE;
  148.     }
  149.     return ret;
  150. }
  151. long HeapNeeded(void)
  152. {
  153.     return (kMinSize * 1024);
  154. }
  155. long StackNeeded(void)
  156. {
  157.     return (kMinSize * 1024);
  158. }
  159.  
  160.